__author__ = 'jason'
""" you must go to https://services.orange.co.uk/sms/sendsms in your browser to get the cookie """


import urllib3

class OrangeSettings():
    def __init__(self):
        self.Url = "https://services.orange.co.uk/sms/sendsms"
        self.RequestMethod = "POST"
        self.FreeOrPhone = 1
        self.LoginUrl = "https://web.orange.co.uk/id/signin.php?rm=StandardSubmit"
        self.LoginUser = ""
        self.LoginPass = ""
        self.ConnectionPool = urllib3.HTTPSConnectionPool()
    def SetUrl(self,NewUrl):
        """changes the default url"""
        self.Url = NewUrl
        try:
            assert isinstance(self.Url, str())
        except TypeError:
            print("New Url is not a string!")

    def SetWebMethod(self,NewRequestMethod):
        """changes the default url"""
        self.RequestMethod = NewRequestMethod
        try:
            assert isinstance(self.RequestMethod, str())
        except TypeError:
            print("New RequestMethod is not a Block Caps string!")

    def SetFreeOrPhone(self,UseOwnPhoneNumber):
        """ takes string 'UseOwnPhoneNumber' | 'UseOrangeServers' or int 0 | 1 """
        if UseOwnPhoneNumber is int:
            try:
                assert(UseOwnPhoneNumber <= 2)
            except Exception:
                print("UseOwnPhoneNumber Must Be Less Than (but not equal to) 2")
            self.FreeOrPhone = UseOwnPhoneNumber
        if UseOwnPhoneNumber is str:
            try:
                assert(UseOwnPhoneNumber == 'UseOwnPhoneNumber'|'UseOrangeServers')
            except:
                print("UseOwnPhoneNumber must equal 'UseOwnPhoneNumber' or 'UseOrangeServers'")
            if UseOwnPhoneNumber == 'UseOwnPhoneNumber':
                self.FreeOrPhone = 1
            else:
                self.FreeOrPhone = 0

    def SetUser(self,NewUser):
        try:
            assert(isinstance(NewUser,str()))
        except TypeError:
            print("NewUser Must Be A String")
        self.LoginUser = NewUser

    def SetPass(self,NewPass):
        try:
            assert(isinstance(NewPass,str()))
        except TypeError:
            print("NewPass Must Be A String")
        self.LoginPass = NewPass
    def SetLoginUrl(self,NewUrl):
        """changes the default url"""
        self.Url = NewUrl
        try:
            assert isinstance(self.Url, str())
        except TypeError:
            print("New Url is not a string!")


class LogIn():
    def __init__(self):
        self.LoginUser = OrangeSettings.LoginUser
        self.LoginPass = OrangeSettings.LoginPass
        self.RememberUser = True

    def Submit(self,ContactNum=self.ContactNum,Message=self.Message):
        """sends the message specified or the message set by getters and setters"""
        method = OrangeSettings.RequestMethod
        url = OrangeSettings.LoginUrl
        #lawl the "resetFields" Javascript function was a givaway
        #and the </form> tag goes at the END of the form. webkit browsers seam awesome these days.
        fields = {
            "sms_from_rad":"1",
            "sendSmsMessageToNumber":ContactNum,
            "sendSmsMessage":Message,
            "Counter":"Allowed"
        }
        try:
            Success = .request_encode_body(method, url, fields, headers=None, encode_multipart=True, multipart_boundary=None""",**urlopen_kw2""") # sould be adequete
        except Exception:
            print(str(Exception))
            print("\n Message not Sent :(")


class Sms():
    def __init__(self):
        self.ContactNum = str("none")
        self.Message = str("none")

    def GetMessage(self):
        return self.Message
    def SetMessage(self,NewMessageStr):
        """set a new message string to be sent, else raise TypeError"""
        try:
            self.Message = str(NewMessageStr)
        except TypeError:
            print("Please Check Message Input is a string or string Convertable")
    def GetContactNum(self):
        """returns the currently stored number"""
        return self.ContactNum
    def SetContactNum(self,NewContactNumStr):
        """set a new ContactNum string to be sent, else raise TypeError"""
        """useful for spamming or mult messaging"""
        try:
            self.ContactNum = str(NewContactNumStr)
        except TypeError:
            print("Please Check ContactNum Input is a string or string Convertable")
    def Send(self,ContactNum=self.ContactNum,Message=self.Message):
        """sends the message specified or the message set by getters and setters"""
        method = OrangeSettings.RequestMethod
        url = OrangeSettings.Url
        #lawl the "resetFields" Javascript function was a givaway
        #and the </form> tag goes at the END of the form. webkit browsers seam awesome these days.
        fields = {
            "sms_from_rad":"1",
            "sendSmsMessageToNumber":ContactNum,
            "sendSmsMessage":Message,
            "Counter":"Allowed"
        }
        OrangeServer = OrangeSettings.ConnectionPool # Lawl - So YOU CAAANN Access class __int__ variables directly
        try:
            Success = OrangeServer.request_encode_body(method, url, fields, headers=None, encode_multipart=True, multipart_boundary=None""",**urlopen_kw2""") # should be adequate
        except Exception:
            print(str(Exception))
            print("\n Message not Sent :(")


